﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterClinicaSanPablo.Master" EnableEventValidation="false"
    AutoEventWireup="true" CodeBehind="MantenimientoCorreo.aspx.cs" Inherits="ClinicaSanPablo.MantenimientoCorreo" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
    <script type="text/javascript">

        $(document).ready(function () {

            $("#ActualizarCorreo").hide("slow");

            $.ajax({
                type: "POST",
                url: "MantenimientoCorreo.aspx/ComboCorreo",
                data: {},
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    var models = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
                    for (var i = 0; i < models.length; i++) {
                        var val = models[i].CodTipCorreo;
                        var text = models[i].DesCripCorreo;
                        $("#CboCorreo").get(0).options[$("#CboCorreo").get(0).options.length] = new Option(text, val);
                    }
                },
                error: function (response) {
                    if (response.length != 0)
                        alert(response);
                }
            });


            $('#btnBuscar').click(function () {
                div = document.getElementById('oculta1');
                div.style.display = "block";
                div = document.getElementById('oculta3');
                div.style.display = "block";
                $("#grdCorreo").trigger("reloadGrid");

                $("#btnActualizar").hide("slow");
                $("#BtnGuardar").hide("slow");

                return false;
            });

            $('#BtnCancelar').click(function () {
                div = document.getElementById('oculta2');
                div.style.display = "none";
                div = document.getElementById('oculta3');
                div.style.display = "none";
                $("#ActualizarCorreo").hide("slow");
                $("#BtnGuardar").show("slow");
                return false;
            });


            $("#grdCorreo").jqGrid({
                url: "BuscarCorreo.aspx",
                datatype: 'json',
                type: 'GET',
                colNames: ['Código', 'Descripción', 'Título', 'Detalle', 'Fecha Actualización'],
                colModel: [
                    { name: 'Id', index: 'Id', align: 'center', width: 100, sortable: false, hidden: true },
                    { name: 'Descripcion', index: 'Descripcion', align: 'center', width: 200, sortable: false },
                    { name: 'TituloCorreo', index: 'TituloCorreo', align: 'center', width: 180, sortable: false },
                    { name: 'Detalle', index: 'Detalle', align: 'center', width: 350, sortable: false },
                    { name: 'FechaActualiza', index: 'FechaActualiza', align: 'center', width: 140, sortable: false },
                    ],
                pager: jQuery('#grdPagerCorreo'),
                rowNum: 20,
                rowList: [20, 50, 100],
                sortname: 'Id',
                sortorder: 'desc',
                postData: {
                    CodCorreo: function () { return $("#CboCorreo option:selected").val(); }
                },
                onSelectRow: function (id) {
                    var ret = jQuery("#grdCorreo").jqGrid('getRowData', id);
                    Codigo = ret.Id;
                    TituloCorreo = ret.TituloCorreo;
                    Detalle = ret.Detalle;
                }
            });


            $("#editFila").click(function () {
                var gr = jQuery("#grdCorreo").getGridParam('selrow');
                if (gr != null) {
                    $("#TxtTituloCorreo").val(TituloCorreo);
                    $("#TxtDetalleCorreo").val(Detalle);
                    div1 = document.getElementById('oculta2');
                    div2 = document.getElementById('oculta3');
                    div1.style.display = "block"                    
                    div2.style.display = "block"
                    $("#ActualizarCorreo").show("slow");
                    $("#BtnGuardar").hide("slow");
                }
                else {
                    alert("Seleccione una fila!");
                }
            });

            $("#ActualizarCorreo").click(function () {

                var valid = $('#form1').valid();

                if (valid) {
                    var txtTituloCorreo = $("#TxtTituloCorreo").val();
                    var txtDetalleCorreo = $("#TxtDetalleCorreo").val();
                    var usuactualiza = $("#LblUsuarioSesion").val();

                    var data3 = {
                        CodTipoCorreo: Codigo,
                        TxtTituloCorreo: txtTituloCorreo,
                        TxtDetalleCorreo: txtDetalleCorreo,
                        Usuactualiza: usuactualiza
                    }

                    var jsondata = JSON.stringify(data3);

                    $.ajax({
                        type: "POST",
                        url: "MantenimientoCorreo.aspx/UpdateCorreo",
                        data: jsondata,
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                            var jsonData = JSON.parse(data.d);
                            if (jsonData.resultado) {
                                alert("Se actualizo el registro");
                                div1 = document.getElementById('oculta2');
                                div2 = document.getElementById('oculta3');
                                div1.style.display = "none";
                                div2.style.display = "none";
                                $("#TxtTituloCorreo").val("");
                                $("#TxtDetalleCorreo").val("");
                                $("#grdCorreo").trigger("reloadGrid");
                            }
                            else {
                                alert("Error al actualizar");
                            }
                        },
                        error: function () {
                            alert("Failed to load names");
                        }
                    });
                }
                return false;
            });

            $('#form1').validate({
                rules: {
                    ctl00$master$TxtTituloCorreo: {
                        required: false
                    },
                    ctl00$master$TxtDetalleCorreo: {
                        required: false
                    }
                }
            });

        });
    </script>
    <style type="text/css">
        .style1
        {
            text-align: left;
        }
        .style2
        {
            width: 82px;
        }
        .style3
        {
            width: 231px;
        }
        .style4
        {
            width: 89px;
        }
        .style5
        {
            width: 6px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="master" runat="server">
    <form id="form1" runat="server">
    <div class="cuerpo">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td colspan="3">
                    <img src="images/caja_main01.gif" width="100%" height="13" />
                </td>
            </tr>
            <tr>
                <td width="7" background="images/caja_main02.gif">
                    &nbsp;
                </td>
                <td class="info" valign="top">
                    <h1>
                        Mantenimiento de <strong>Córreo<asp:ScriptManager ID="ScriptManager1" runat="server"
                            EnablePageMethods="True">
                        </asp:ScriptManager>
                        </strong>
                    </h1>
                    <div class="content" style="margin-bottom: 10px;">
                        <table border="0" cellspacing="0" cellpadding="0" style="height: 75px; width: 100%"
                            class="TablaStyle">
                            <%--   <tr>
                                      <td width="6"><img src="images/cajaN_01.gif" width="6" height="6" /></td>
                                      <td background="images/cajaN_02.gif"><img src="images/space.gif" width="10" height="5" /></td>
                                      <td width="6"><img src="images/cajaN_03.gif" width="6" height="6" /></td>
                                    </tr>--%>
                            <tr>
                                <%--<td width="6" background="images/cajaN_04.gif">&nbsp;</td>--%>
                                <td bgcolor="#eeeeee">
                                    <h2>
                                        Búsqueda de Córreo:</h2>
                                    <table width="95%" border="0" align="center" cellpadding="1" cellspacing="1">
                                        <tr>
                                            <td class="style2">
                                                <strong>Descripción:</strong>
                                            </td>
                                            <td class="style3">
                                                <asp:DropDownList ID="CboCorreo" runat="server" Width="212px" Height="22px">
                                                    <asp:ListItem>--Seleccione--</asp:ListItem>
                                                </asp:DropDownList>
                                            </td>
                                            <td align="right" class="style1">
                                                <button id="btnBuscar" class="submitBtn">
                                                    <span>Buscar</span></button>
                                                <asp:HiddenField ID="LblUsuarioSesion" runat="server" />
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                                <%--<td width="6" background="images/cajaN_05.gif">&nbsp;</td>--%>
                            </tr>
                            <%--<tr>
                                  <td width="6"><img src="images/cajaN_06.gif" width="6" height="6" /></td>
                                  <td background="images/cajaN_07.gif"><img src="images/space.gif" width="10" height="5" /></td>
                                  <td width="6"><img src="images/cajaN_08.gif" width="6" height="6" /></td>
                                </tr>--%>
                        </table>
                    </div>
                    <%--style="display:none; margin-bottom:10px;"--%>
                    <div class="content" id="oculta1" style="display:none; margin-bottom:10px;">
                        <table width="100%" border="0" class="TablaStyle" cellspacing="0" cellpadding="0">
                            <%--  <tr>
                                    <td class="style5"><img src="images/cajaN_01.gif" width="6" height="6" /></td>
                                    <td background="images/cajaN_02.gif"><img src="images/space.gif" width="10" height="5" /></td>
                                    <td width="6"><img src="images/cajaN_03.gif" width="6" height="6" /></td>
                                  </tr>--%>
                            <tr>
                                <td >
                                    &nbsp;
                                </td>
                                <td bgcolor="#eeeeee">
                                    <h2>
                                        Resultado:</h2>
                                    <div style="width: 100%;" id="asd" align="center">
                                        <table id="grdCorreo">
                                        </table>
                                    </div>
                                    <div id="grdPagerCorreo" align="center">
                                    </div>
                                    &nbsp;
                                    <input type="button" value="" id="editFila" />
                                </td>
                                <%--<td width="6" background="images/cajaN_05.gif">&nbsp;</td>--%>
                            </tr>
                            <tr>
                                <td class="style5">
                                    &nbsp;
                                </td>
                                <td bgcolor="#eeeeee">
                                    &nbsp;
                                </td>
                                <td width="6">
                                    &nbsp;
                                </td>
                            </tr>
                            <%--<tr>
    <td class="style5"><img src="images/cajaN_06.gif" width="6" height="6" /></td>
    <td background="images/cajaN_07.gif"><img src="images/space.gif" width="10" height="5" /></td>
    <td width="6"><img src="images/cajaN_08.gif" width="6" height="6" /></td>
  </tr>--%>
                        </table>
                    </div>
                    <%--style="display: none;"--%>
                    <div class="content" id="oculta2" style="display: none;">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="TablaStyle">
                            <tr>
                                <td width="6">
                                </td>
                                <td>
                                </td>
                                <td width="6">
                                </td>
                            </tr>
                            <tr>
                                <td width="6">
                                    &nbsp;
                                </td>
                                <td bgcolor="#eeeeee">
                                    <h2>
                                        Editar Correo</h2>
                                    <table width="95%" border="0" align="center" cellpadding="2" cellspacing="1">
                                        <tr>
                                            <td class="style4">
                                                Título correo :
                                            </td>
                                            <td>
                                                <asp:TextBox ID="TxtTituloCorreo" runat="server" CssClass="frm" Width="300px"></asp:TextBox>
                                            </td>
                                            <td align="right">
                                                &nbsp;
                                            </td>
                                            <td>
                                                &nbsp;
                                            </td>
                                            <td align="right">
                                                &nbsp;
                                            </td>
                                            <td>
                                                &nbsp;
                                            </td>
                                        </tr>
                                        <tr>
                                            <td valign="top" class="style4">
                                                Detalle correo :
                                            </td>
                                            <td>
                                                <asp:TextBox ID="TxtDetalleCorreo" runat="server" Height="56px" TextMode="MultiLine"
                                                    Width="718px" CssClass="frm"></asp:TextBox>
                                            </td>
                                            <td align="right">
                                                &nbsp;
                                            </td>
                                            <td>
                                                &nbsp;
                                            </td>
                                            <td align="right">
                                                &nbsp;
                                            </td>
                                            <td>
                                                &nbsp;
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class="style4">
                                                &nbsp;
                                            </td>
                                            <td>
                                                &nbsp;
                                            </td>
                                            <td align="right">
                                                &nbsp;
                                            </td>
                                            <td>
                                                &nbsp;
                                            </td>
                                            <td align="right">
                                                &nbsp;
                                            </td>
                                            <td>
                                                &nbsp;
                                            </td>
                                        </tr>
                                    </table>
                                    <p>
                                        &nbsp;</p>
                                </td>
                                <td width="6"s>
                                    &nbsp;
                                </td>
                            </tr>
                            <tr>
                                <td width="6">
                                </td>
                                <td>
                                </td>
                                <td width="6">
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div id="oculta3" style="display: none;">
                        <p align="center">
                            <button id="ActualizarCorreo" class="submitBtn" style="display: none">
                                <span>Actualizar</span></button>
                            <button id="BtnGuardar" class="submitBtn">
                                <span>Guardar</span></button>
                            <button id="BtnCancelar" class="submitBtn">
                                <span>Cancelar</span></button>
                            <button id="BtnLimpiar" class="submitBtn">
                                <span>Limpiar</span></button>
                        </p>
                    </div>
                </td>
                <td width="7" background="images/caja_main03.gif">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <img src="images/caja_main04.gif" width="973" height="13" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</asp:Content>
